<%@page import="it.sauronsoftware.base64.Base64"%>
<%@page import="multiface.awwadco.jpa.Utente"%>
<%
    Utente ut = (Utente) session.getAttribute("admin");
    if (ut == null) {
        response.sendRedirect(multiface.web.util.ServletUtils.getBaseUrl(request) + "/admin/index.jsp?err=y");
    }
%>
<%@page import="multiface.web.util.PagerList"%>
<%@page import="javax.persistence.Query"%>
<%@page import="java.util.LinkedList"%>
<%@page import="java.util.Iterator"%>
<%@page import="multiface.awwadco.jpa.Opzioni"%>
<%@page import="java.util.List"%>
<%@page import="javax.persistence.RollbackException"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="javax.persistence.Persistence"%>
<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="multiface.awwadco.jpa.Categoria"%>
<%@page import="multiface.awwadco.jpa.File"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="multiface.awwadco.jpa.PersistenceManager"%>
<style type="text/css">
    .des_hp{display: none}
</style>

<script type="text/javascript">
    $("#homepage").live('click', function() {
        if ($("#homepage").attr('checked') == "checked") {
            $(".des_hp").fadeIn(400);
        } else {
            $(".des_hp").fadeOut(400);
        }
    });
</script>

<script type="text/javascript">
    // codice javascript per il validator dei campi 
</script>

<div class="box" id="box-1">
    <form class="formBox" id="formBox" method="post" action="">
        <%
            Utente u = (Utente) session.getAttribute("admin");
            //Sy_stem.out.println("Amministratore: " + u.getNome() + " " + u.getCognome() + ", " + u.getTipo());

            EntityManagerFactory emf = PersistenceManager.getInstance().getEntityManagerFactory();
            EntityManager em = emf.createEntityManager();

            //String pid = request.getParameter("pid");

            Opzioni p = em.createNamedQuery("Opzioni.findAll", Opzioni.class).getSingleResult();

            em.close();

            String sel_plain = "";
            String sel_sls = "";
            String sel_tls = "";

            if (p.getSmtpStrategy().equalsIgnoreCase("SMTP_PLAIN")) {
                sel_plain = "selected";
            }
            if (p.getSmtpStrategy().equalsIgnoreCase("SMTP_TLS")) {
                sel_tls = "selected";
            }
            if (p.getSmtpStrategy().equalsIgnoreCase("SMTP_SSL")) {
                sel_sls = "selected";
            }
        %>
        <div class="title">Option's site</div>
        <br>

        <div class="inputs">
            <label for="emailcontatto">E-mail contact</label>
            <input name="emailcontatto" id="emailcontatto" maxlength="255" type="text" value="<%=p.getEmailContatto()%>"/>
        </div>

        <div class="inputs">
            <label for="smtphost">SMTP host</label>
            <input name="smtphost" id="smtphost" maxlength="255" type="text" value="<%=p.getSmtpHost()%>"/>
        </div>

        <div class="inputs">
            <label for="smtphost">SMTP port</label>
            <input name="smtpport" id="smtpport" maxlength="255" type="text" value="<%=p.getSmtpPort()%>"/>
        </div>

        <div class="inputs">
            <label for="smtphost">SMTP Transport Strategy</label>
            <select style="margin: 6px;" name="smtpstrategy" id="smtpstrategy">
                <option value="SMTP_PLAIN" <%=sel_plain%> >Plain</option>
                <option value="SMTP_SSL" <%=sel_sls%> >SSL</option>SMTP_TLS
                <option value="SMTP_TLS" <%=sel_tls%> >TLS</option>
            </select>
        </div>

        <div class="inputs">
            <label for="smtpuser">SMTP user</label>
            <input name="smtpuser" id="smtpuser" maxlength="255" type="text" value="<%=p.getSmtpUser()%>"/>
        </div>

        <div class="inputs">
            <label for="smtppassword">SMTP password</label>
            <input name="smtppassword" id="smtppassword" maxlength="255" type="password" value="<%=Base64.decode(p.getSmtpPassword())%>"/>
        </div>

        <div class="inputs">
            <label for="maxrecordpag">Max record for page</label>
            <select style="margin: 6px;" name="maxrecordpag" id="maxrecordpag">
                <%
                    for (int i = 10; i <= 200; i++) {
                        if (i == p.getMaxRecordPag()) {
                            out.println("<option selected value=\"" + i + "\">" + i + "</option>");
                        } else {
                            out.println("<option value=\"" + i + "\">" + i + "</option>");
                        }
                    }
                %>
            </select>
        </div>

        <div class="inputs">
            <label for="maxrecordpagadmin">Max record for page for administration</label>
            <select style="margin: 6px;" name="maxrecordpagadmin" id="maxrecordpagadmin">
                <%
                    for (int i = 10; i <= 200; i++) {
                        if (i == p.getMaxRecordPagAdmin()) {
                            out.println("<option selected value=\"" + i + "\">" + i + "</option>");
                        } else {
                            out.println("<option value=\"" + i + "\">" + i + "</option>");
                        }
                    }
                %>
            </select>
        </div>

        <div class="inputs">
            <label for="maxrecordpagadmin">Title of the News Automate for Promo</label>
            <input style="float: left;" class="legend" id="news_title_promo" maxlength="255" type="text" value="<%=p.getAutoTitleNewsPromo()%>"/>
        </div>
        <div class="inputs">
            <label for="maxrecordpagadmin">Text of the News Automate for Promo</label>
            <textarea class="legend" rows="10" id="news_text_promo"><%=p.getAutoTextNewsPromo()%></textarea>
            <div class="legend">[PRODUCT:NAME] = Product Name</div>
            <div class="legend">[PRODUCT:MODEL] = Product Model</div>
            <div class="legend">[PRODUCT:PRICE] = Product Price</div>
            <div class="legend">[PRODUCT:LINK] = Link Product Details</div>
            <div class="legend">[BR] = Carriage Return</div>
        </div>

        <input name="idopzioni" id="idopzioni" type="hidden"  value="<%=p.getIdopzioni()%>"/>
    </form>
    <div id="result"></div>
</div>
<style>
    .legend{
        font-size: 11px;
        font-family: monospace;
    }
</style>